package gdconf

import (
	"server_cluster/common/logger"
)

// 家园农田种子配置表

type HomeFarmSeedConfig struct {
	SeedId     int32    `csv:"SeedID" gorm:"primary_key;autoIncrement:false"` // 种子id
	GatherTime int32    `csv:"MatureTime,omitempty"`                          // 成熟时间 分
	RewardItem ItemList `csv:"Reward,omitempty"`                              // 收获奖励道具
}

func (h *HomeFarmSeedConfig) TableName() string {
	return "config_home_farm_seed"
}

func (g *GameDataConfig) saveHomeFarmSeedConfig() {
	saveTableToDb[HomeFarmSeedConfig](g.Db, readTable[HomeFarmSeedConfig](g.CsvPathPrefix+"HomeFarmLand.csv"))
}

func (g *GameDataConfig) loadHomeFarmSeedConfig() {
	g.GameDataMaps.HomeFarmSeedConfigMap = make(map[int32]*HomeFarmSeedConfig)
	for _, homeFarmSeedConfig := range loadTableFromDb[HomeFarmSeedConfig](g.Db) {
		g.GameDataMaps.HomeFarmSeedConfigMap[homeFarmSeedConfig.SeedId] = homeFarmSeedConfig
	}
	logger.Info("HomeFarmSeedConfig Count: %v", len(g.GameDataMaps.HomeFarmSeedConfigMap))
}

func GetHomeFarmSeedConfig(seedId int32) *HomeFarmSeedConfig {
	value, exist := CONF.GameDataMaps.HomeFarmSeedConfigMap[seedId]
	if !exist {
		logger.Error("[ConfigNotFound] HomeFarmSeedConfig, seedId: %v", seedId)
		return nil
	}
	return value
}

func GetHomeFarmSeedConfigMap() map[int32]*HomeFarmSeedConfig {
	return CONF.GameDataMaps.HomeFarmSeedConfigMap
}
